local tanhu = fk.CreateSkill {
  name = "lvshi__tanhu",
}

Fk:loadTranslationTable{
  ["lvshi__tanhu"] = "探虎",
  [":lvshi__tanhu"] = "阶段技，你可展示任意张【杀】或锦囊牌并观看一名其他角色的手牌，你令其弃置其中一种花色的牌，若不为你展示牌的花色，你不能再对其发动此技能。",
  ["#lvshi__tanhu"] = "请选择任意张【杀】或锦囊牌和一名有手牌的角色",
  ["#lvshi__tanhu-throw"] = "探虎：弃置 %dest 一种花色的手牌",
  ["@[player]lvshi__tanhu"] = "探虎",
  ["$lvshi__tanhu1"] = "此速攻可胜，切莫筑室道谋！",
  ["$lvshi__tanhu2"] = "生死存亡之道，不可不察！",
}

local U = require "packages/utility/utility"

tanhu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lvshi__tanhu",
  min_card_num = 1,
  target_num = 1,
  max_phase_use_time = 1,
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select).type == Card.TypeTrick or Fk:getCardById(to_select).trueName == "slash"
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return to_select ~= player and not to_select:isKongcheng()
    and not table.contains(player:getTableMark("@[player]lvshi__tanhu"), to_select.id)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    player:showCards(effect.cards)
    local to_throw = {}
    local listNames = {"log_spade", "log_club", "log_heart", "log_diamond"}
    local listCards = { {}, {}, {}, {} }
    local can_throw
    for _, id in ipairs(to:getCardIds("h")) do
      local suit = Fk:getCardById(id).suit
      if suit ~= Card.NoSuit then
        table.insertIfNeed(listCards[suit], id)
        can_throw = true
      end
    end
    if can_throw then
      local choice = U.askForChooseCardList(room, player, listNames, listCards, 1, 1, tanhu.name,
        "#lvshi__tanhu-throw::"..to.id, false, false)
      if #choice == 1 then
        to_throw = table.filter(to:getCardIds("h"), function(id)
          return Fk:getCardById(id):getSuitString(true) == choice[1]
        end)
      end
      if not table.find(effect.cards, function (id)
        return Fk:getCardById(id):getSuitString(true) == choice[1]
      end) then
        room:addTableMarkIfNeed(player, "@[player]lvshi__tanhu", to.id)
      end
    end
    room:throwCard(to_throw, tanhu.name, to, player)
  end,
})

return tanhu
